//
//  MainViewController.swift
//  sinaweibo
//
//  Created by IZEN on 16/3/6.
//  Copyright © 2016年 IZEN. All rights reserved.
//

import UIKit

class MainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        //调整tabbar
        
        let mainTabBar = MainTabBar()
        mainTabBar.plusBtn.addTarget(self, action: "plusBtnClick", forControlEvents: .TouchUpInside)
        setValue(mainTabBar, forKey: "tabBar")
    
        addChildViewControllers()
    }
    @objc private func plusBtnClick() {
        print("plus")
    }
    
    private func addChildViewControllers() {
        
        addChildViewController(HomeTableViewController(), title: "首页", imageName: "tabbar_home")
        addChildViewController(MessageTableViewController(), title: "消息", imageName: "tabbar_message_center")
        addChildViewController(DiscoverTableViewController(), title: "发现", imageName: "tabbar_discover")
        addChildViewController(ProfileTableViewController(), title: "我", imageName: "tabbar_profile")
    }
    
    private func addChildViewController(vc: UIViewController,title: String, imageName: String) {
        vc.title = title
        vc.tabBarItem.title = title
        
//        tabBar.tintColor = UIColor.orangeColor()
        
        vc.tabBarItem.image = UIImage(named: imageName)
        
        
        vc.tabBarItem.selectedImage = UIImage(named: imageName + "_selected")?.imageWithRenderingMode(.AlwaysOriginal)
        let nav = UINavigationController(rootViewController: vc)
        addChildViewController(nav)
        
    }
    
    

}
